package cayte.demo.dict;

import java.util.ArrayList;

public class DictData {
	public ArrayList<Word> words = new ArrayList<Word>();
	public static final int COUNT = 50;

	private static DictData dict;

	private DictData() {
	}

	public static DictData instance() {
		if (dict == null) {
			dict = new DictData();
		}
		return dict;
	}

	public void init() {
		words = new ArrayList<Word>();
	}

	public void add(String en, String cn) {
		Word word = new Word();
		word.setNum(words.size());
		word.setEn(en);
		word.setCn(cn);
		words.add(word);
	}

	public ArrayList<Word> getAll() {
		return words;
	}

	public ArrayList<Word> get(int i) {
		ArrayList<Word> res = new ArrayList<Word>();
		if (COUNT * (i + 1) > words.size()) {
			for (int x = COUNT * i, y = words.size(); x < y; x++) {
				res.add(words.get(x));
			}
			return res;
		} else {
			for (int x = COUNT * i, y = COUNT * (i + 1); x < y; x++) {
				res.add(words.get(x));
			}
			return res;
		}
	}
}
